package maildao

import (
	"context"
	"github.com/gogf/gf/v2/frame/g"
	"xr-game-server/core/cache"
	"xr-game-server/entity"
)

var roleSysMailCache *cache.CacheMgr

func initRoleSysMail() {
	roleSysMailCache = cache.NewCacheMgr()
}
func GetRoleSysMail(roleId uint64, mailId uint64) *entity.RoleSysMail {
	db := roleSysMailCache.GetData(roleId, func(ctx context.Context) (value interface{}, err error) {
		var ret *entity.RoleSysMail
		g.Model(string(entity.TbRoleSysMail)).Unscoped().Where(g.Map{
			string(entity.RoleSysMailRoleId): roleId,
			string(entity.RoleSysMailMailId): mailId,
		}).Scan(&ret)
		if ret == nil {
			ret = entity.NewRoleSysMail(roleId, mailId)
		}
		return ret, nil
	})
	return db.(*entity.RoleSysMail)
}
